Marcin Beer Data
384
1427
1460
Default sorting by global rating
---
title: "Beer Analytics"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
theme: 'bootstrap'
---
```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(DT)
library(highcharter)
library(rpivotTable)
library(ggplot2)
library(openintro)
library(dplyr)
library(tidyverse)
library(plotly)
library(maps)
```
```{r}
data <- read.csv("~/Documents/GitHub/beer-data/data.csv")
DEdata <- read.csv("~/Documents/GitHub/beer-data/delaware-breweries.csv")
#visitData <- read.csv("~/Documents/GitHub/beer-data/visitData.csv")
```
```{r}
dataUnique <- data
dataUnique <- distinct(dataUnique, beer_name, .keep_all = TRUE)
stateCount <- dataUnique %>% group_by(brewery_state) %>%
dplyr::summarize(count = n()) %>%
arrange(desc(count))
stateCount$brewery_state <- abbr2state(stateCount$brewery_state)
#stateCountVisited <- visitData %>% group_by(brewery_state) %>%
# dplyr::summarize(count = n()) %>%
# arrange(desc(count))
# stateCountVisited$brewery_state <- abbr2state(stateCountVisited$brewery_state)
```
```{r}
countryCount <- data %>% group_by(brewery_country) %>%
dplyr::summarize(count = n()) %>%
arrange(desc(count))
```
```{r}
typeCount <- data %>% select('beer_type','rating_score')
typeCount <- typeCount %>%
mutate(beer_type = replace(beer_type, beer_type == 'Sour - Fruited', 'Sour')) %>%
mutate(beer_type = replace(beer_type, beer_type == '*IPA*', 'IPA'))
typeCount <- data %>% group_by(beer_type) %>%
dplyr::summarize(count = n()) %>%
arrange(desc(count))
```
```{r}
countryRatings <- data %>% select('brewery_country','rating_score','global_rating_score')
countryRatings <- setNames(aggregate(countryRatings[,2:3], list(countryRatings$brewery_country),
mean) %>% mutate_if(is.numeric, round, digits=2), c('brewery_country', 'AverageRating', 'GlobalRating'))
countCountries <- data %>% group_by(brewery_country) %>%
dplyr::summarize(count = n()) %>%
arrange(desc(count))
countryRatings <- full_join(countryRatings,countCountries, by = 'brewery_country') %>%
arrange(desc(AverageRating))
countryRatings <- filter(countryRatings, count >= 5)
countryRatings <- head(countryRatings, 10)
```
```{r}
breweriesFormatted <- data %>% select('brewery_name','rating_score')
breweriesFormattedUnique <- data %>% select('beer_name','brewery_name','rating_score','brewery_state')
breweriesFormattedUnique <- unique(breweriesFormattedUnique, by = "beer_name")
breweriesFormatted <- setNames(aggregate(breweriesFormatted[,2], list(breweriesFormatted$brewery_name), mean) %>% mutate_if(is.numeric, round, digits=2), c('brewery_name', 'AverageRating'))
breweriesFormatted<- breweriesFormatted[order(-breweriesFormatted$AverageRating), ]
topBreweries <- breweriesFormatted
topBreweries <- breweriesFormatted[order(-topBreweries$AverageRating), ]
countBreweries <- data %>% group_by(brewery_name) %>%
dplyr::summarize(count = n()) %>%
arrange(desc(count))
```
Home
==================
Row
------------------
### Data Refreshed July 9, 2022
```{r}
valueBox(paste('Marcin Beer Data'),
color = '#7e868f')
```
### Unique Breweries
```{r}
ss <- 1
valueBox(length(countBreweries$brewery_name),
icon = 'fa-tree')
```
### Unique Beers
```{r}
valueBox(length(breweriesFormattedUnique$beer_name),
icon = 'fa-beer')
```
### Personal Average Score
```{r}
gauge(round(mean(data$rating_score),
digits = 2),
min = 0,
max = 5,
gaugeSectors(success = c(0,2),
warning = c(2,4),
danger = c(4,5),
colors = c('red','yellow','green')))
```
### Global Average Score of Sample
```{r}
gauge(round(mean(data$global_rating_score),
digits = 2),
min = 0,
max = 5,
gaugeSectors(success = c(0,2),
warning = c(2,4),
danger = c(4,5),
colors = c('red','yellow','green')))
```
### Total Number of Check-Ins
```{r}
valueBox(length(data$beer_name),
icon = 'fa-pencil')
```
Column {data-width=350}
-----------------------------------------------------------------------
### Top 15 Breweries With Minimum 5 Samples
```{r}
mergedData <-
full_join(topBreweries,countBreweries, by = 'brewery_name')
mergedData <- filter(mergedData, count > 4) %>%
arrange(desc(AverageRating))
mergedData <- setNames(mergedData, c('Brewery','AverageRating','Count'))
mergedData <- head(mergedData, 15)
mergedData$Brewery <- factor(mergedData$Brewery, levels = unique(mergedData$Brewery)[order(mergedData$AverageRating, decreasing = TRUE)])
topBreweryPlot <- plot_ly(mergedData,
x = ~Brewery,
y = ~AverageRating,
ascending = TRUE,
text = ~AverageRating,
textposition = 'auto',
type = 'bar') %>%
layout( xaxis = list(title = "Brewery"),
yaxis = list(title = "Average Rating")
) %>%
layout(showlegend = FALSE)
topBreweryPlot
```
### Top Countries With Sample Size 5 or More
```{r}
countryRatings$brewery_country <- factor(countryRatings$brewery_country, levels = unique(countryRatings$brewery_country)[order(countryRatings$AverageRating, decreasing = TRUE)])
topCountryPlot <- plot_ly(countryRatings,
x = ~brewery_country,
y = ~AverageRating,
ascending = TRUE,
name = 'Personal Rating',
type = 'bar') %>%
layout( xaxis = list(title = "Country"),
yaxis = list(title = "Average Rating")
) %>%
layout(showlegend = TRUE)
topCountryPlot <- topCountryPlot %>%
add_trace(y = ~GlobalRating,
name = 'Global Rating')
topCountryPlot
```
Row
-------------------------
### Distribution of Ratings, Handpicked 8 Breweries (Personal Favorites)
```{r}
### Sorry, these are hard-coded for now :-)
TreeHouseRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Tree House Brewing Company')
GrimmRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Grimm Artisanal Ales')
EPRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Elder Pine Brewing & Blending')
AdroitRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Adroit Theory')
TARatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Tripping Animals Brewing Co.')
BurialRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Burial Beer Co.')
EquilibriumRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Equilibrium Brewery')
BurleyRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Burley Oak Brewing Company')
NepentheRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Nepenthe Brewing Co.')
OHRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Other Half Brewing Co.')
AveryRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Avery Brewing Co.')
DrekkerRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Drekker Brewing Company')
AbominationRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Abomination Brewing Company')
GreatNotionRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Great Notion Brewing')
DeliriumRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Delirium - Huyghe Brewery')
ToppingGoliathRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Topping Goliath Brewing Co.')
AnchorageRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Anchorage Brewing Company')
HudsonValleyRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Hudson Valley Brewery')
TroonRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == 'Troon Brewing')
TwoStonesRatings <-data.frame(data$brewery_name, data$rating_score) %>%
filter(data.brewery_name == '2SP Brewing Company')
### These too ;-)
TreeHouseRatings <-setNames(TreeHouseRatings, c('Brewery Name','Rating'))
AnchorageRatings <-setNames(AnchorageRatings, c('Brewery Name','Rating'))
GrimmRatings <-setNames(GrimmRatings, c('Brewery Name','Rating'))
EPRatings <-setNames(EPRatings, c('Brewery Name','Rating'))
AdroitRatings <-setNames(AdroitRatings, c('Brewery Name','Rating'))
TARatings <-setNames(TARatings, c('Brewery Name','Rating'))
BurialRatings <-setNames(BurialRatings, c('Brewery Name','Rating'))
EquilibriumRatings <-setNames(EquilibriumRatings, c('Brewery Name','Rating'))
BurleyRatings <-setNames(BurleyRatings, c('Brewery Name','Rating'))
NepentheRatings <-setNames(NepentheRatings, c('Brewery Name','Rating'))
OHRatings <-setNames(OHRatings, c('Brewery Name','Rating'))
AveryRatings <-setNames(AveryRatings, c('Brewery Name','Rating'))
DrekkerRatings <-setNames(DrekkerRatings, c('Brewery Name','Rating'))
AbominationRatings <-setNames(AbominationRatings, c('Brewery Name','Rating'))
GreatNotionRatings <-setNames(GreatNotionRatings, c('Brewery Name','Rating'))
DeliriumRatings <-setNames(DeliriumRatings, c('Brewery Name','Rating'))
ToppingGoliathRatings <-setNames(ToppingGoliathRatings, c('Brewery Name','Rating'))
HudsonValleyRatings <-setNames(HudsonValleyRatings, c('Brewery Name','Rating'))
TroonRatings <-setNames(TroonRatings, c('Brewery Name','Rating'))
TwoStonesRatings <-setNames(TwoStonesRatings, c('Brewery Name','Rating'))
beerBox <- plot_ly(y = TroonRatings$Rating, type = "box", name = 'Troon')
beerBox <- beerBox %>% add_trace(y = AnchorageRatings$Rating, type = "box", name = 'Anchorage')
beerBox <- beerBox %>% add_trace(y = TreeHouseRatings$Rating, type = "box", name = 'Tree House')
beerBox <- beerBox %>% add_trace(y = GrimmRatings$Rating, type = "box", name = 'Grimm')
beerBox <- beerBox %>% add_trace(y = TwoStonesRatings$Rating, type = "box", name = 'Two Stones')
beerBox <- beerBox %>% add_trace(y = EPRatings$Rating, type = "box", name = 'Elder Pine')
#beerBox <- beerBox %>% add_trace(y = DeliriumRatings$Rating, type = "box", name = 'Delirium')
beerBox <- beerBox %>% add_trace(y = AdroitRatings$Rating, type = "box", name = 'Adroit Theory')
#beerBox <- beerBox %>% add_trace(y = DrekkerRatings$Rating, type = "box", name = 'Drekker')
#beerBox <- beerBox %>% add_trace(y = GreatNotionRatings$Rating, type = "box", name = 'Great Notion')
#beerBox <- beerBox %>% add_trace(y = TARatings$Rating, type = "box", name = 'Tripping Animals')
#beerBox <- beerBox %>% add_trace(y = BurialRatings$Rating, type = "box", name = 'Burial')
#beerBox <- beerBox %>% add_trace(y = AbominationRatings$Rating, type = "box", name = 'Abomination')
#beerBox <- beerBox %>% add_trace(y = ToppingGoliathRatings$Rating, type = "box", name = 'ToppingGoliathRatings')
#beerBox <- beerBox %>% add_trace(y = EquilibriumRatings$Rating, type = "box", name = 'Equilibrium')
#beerBox <- beerBox %>% add_trace(y = BurleyRatings$Rating, type = "box", name = 'Burley Oak')
#beerBox <- beerBox %>% add_trace(y = NepentheRatings$Rating, type = "box", name = 'Nepenthe')
beerBox <- beerBox %>% add_trace(y = OHRatings$Rating, type = "box", name = 'Other Half')
#beerBox <- beerBox %>% add_trace(y = AveryRatings$Rating, type = "box", name = 'Avery')
beerBox
```
US State Map
=========================
```{r}
s <- map_data('state')
highchart() %>%
hc_title(text = "Count of Beers by State") %>%
hc_subtitle(text = "Heatmap") %>%
hc_add_series_map(usgeojson, stateCount,
name = 'brewery_state',
value = 'count',
joinBy = c("woename", "brewery_state")) %>%
hc_colorAxis(minColor = "#30c95c", maxColor = "darkgreen") %>%
hc_mapNavigation(enabled = T)
```
World Map
=========================
```{r}
highchart() %>%
hc_title(text = "Count of Beers by Country") %>%
hc_subtitle(text = "Heatmap") %>%
hc_add_series_map(worldgeojson, (countryCount %>%
mutate(brewery_country = replace(brewery_country, brewery_country == 'United States', 'United States of America'))
%>% mutate(brewery_country = replace(brewery_country, brewery_country == 'England', 'United Kingdom'))
%>% mutate(brewery_country = replace(brewery_country, brewery_country == "China / People's Republic of China", 'China'))),
name = 'brewery_country',
value = 'count',
joinBy = c("name", "brewery_country")) %>%
hc_colorAxis(minColor = "green", maxColor = "darkgreen") %>%
hc_mapNavigation(enabled = T)
```
```{r}
### s <- map_data('state')
### highchart() %>%
### hc_title(text = "Count of Beers by State") %>%
### hc_subtitle(text = "Heatmap") %>%
### hc_add_series_map(usgeojson, stateCountVisited,
### name = 'brewery_state',
# value = 'count',
# joinBy = c("woename", "brewery_state")) %>%
# hc_colorAxis(minColor = "#30c95c", maxColor = "darkgreen") %>%
# hc_mapNavigation(enabled = T)
```
Filter Table
========================
Default sorting by global rating
```{r}
dataSummary <- data %>% select('brewery_name','beer_name','brewery_country', 'brewery_state', 'rating_score', 'global_rating_score')
dataSummary <- unique(dataSummary, by = "beer_name")
breweriesFormattedUnique <- unique(breweriesFormattedUnique, by = "beer_name")
dataSummary <- data.frame(
dataSummary$brewery_name,
dataSummary$beer_name,
dataSummary$brewery_country,
abbr2state(breweriesFormattedUnique$brewery_state),
dataSummary$rating_score,
dataSummary$global_rating_score,
round(abs((dataSummary$global_rating_score)-(dataSummary$rating_score)), digits = 2))
dataSummary <- setNames(dataSummary, c('Brewery Name','Beer Name','Brewery Country','Brewery State', 'My Rating', 'Global Rating', 'Rating Difference'))
datatable(dataSummary,
caption = 'Full Ratings Table',
rownames = T,
filter = 'top',
options= list(
pageLength = 100,
order = list(list(6, 'desc')),
scrollY = "700",
rowCallback = JS("function(r,d) {$(r).attr('height', '50px')}")))
```
State Count
========================
```{r}
stateCount <- stateCount %>% drop_na()
stateNames <- data.frame(state.name)
stateCount <- setNames(stateCount, c('state.name', 'Count'))
stateMetrics <- full_join(stateNames, stateCount, 'state.name')
stateMetrics <- stateMetrics %>% dplyr::mutate(Count = replace_na(Count, 0))
stateMetrics <- setNames(stateMetrics, c('State Name', 'Count'))
datatable(stateMetrics,
caption = 'Count of Unique Beers per State',
rownames = T,
filter = 'top',
options = list(pageLength = 52,
scrollY='700px'))
```
Delaware Breweries
========================
```{r}
DEdata <- read.csv("~/Documents/GitHub/beer-data/delaware-breweries.csv")
DEdata <- merge(topBreweries, DEdata, by = 'brewery_name', all.y = TRUE)
datatable(DEdata,
caption = 'Full Ratings Table',
colname = c('Brewery','Personal Rating','Tried?','Visited?','Locations'),
rownames = T,
filter = 'top',
options= list(
pageLength = 35,
scrollY = "400",
rowCallback = JS("function(r,d) {$(r).attr('height', '50px')}")))
```